# -*- coding: utf-8 -*-

import sip
sip.setapi('QString', 2)
sip.setapi('QStringList', 2)
sip.setapi('QVariant', 2)

from PyQt4 import QtCore
import mpd

#_______________________________________________________________________________
class QueryStatus(QtCore.QThread):
    idle_notified = QtCore.pyqtSignal(list)
    
    def __init__(self, client, info):
        QtCore.QThread.__init__(self)
        self.client = mpd.MPDClient()
        self.client.connect(info["host"], info["port"])
        self.term = False
    
    def run(self):
        while self.term is False:
            subsystem_list = self.client.idle()
            if len(subsystem_list) > 0:
                self.idle_notified.emit(subsystem_list)

    def stop(self):
        self.term = True
        self.client.noidle()
        self.client.close()
        self.client.disconnect()
